from os import error
from flask import Blueprint,render_template, request,session,redirect
from config import conn,cur,mutex ,r as redis
import datetime

Medication = Blueprint('Medication',__name__)
 
@Medication.route('/',methods=["GET", "POST"])
def index():
    id = session.get('id') 
    name = session.get('name')

    sqlstr='select name, time from medication where patient_id= \'' + str(id)+'\''
    print(sqlstr)
    cur.execute(sqlstr)
    result = cur.fetchall()
    
    return render_template('/medication/index.html',id=id,name=name,data=result)



@Medication.route('/logout',methods=["GET", "POST"])
def logout():
    session.clear()
    return {
        'message':"success!"
    }


@Medication.before_request
def before():
    if session.get('id') is None or session.get('role') != 'patient':
        return redirect('/Login/',code=301)
    else:
        pass